<template>
  <div class="productDetail" :style="availHeight">
    <nav-bar :title="department.name" :goback="true"></nav-bar>
    <div class="goto-list" @click="collection">收藏</div>
    <div class="gap">
      <van-swipe class="img" v-if="showImg" :autoplay="3000" indicator-color="#06A44F">
        <van-swipe-item v-for="(val,key) in imgList" :key="key">
          <img :src="val" />
        </van-swipe-item>
      </van-swipe>
      <section class="department">
        <p class="product-price" v-html="'￥'+price" v-show="price != '' ? true:false"/>
        <p class="vip-price" v-html="'会员最低价￥'+vipPrice" v-show="price != '' ? true:false"/>
        <p class="department-name">{{department.name}}</p>
        <p class="department-detail">{{department.detail}}</p>
      </section>
      <section class>
        <van-tabs class="tabs" type="card" background="#F5F5F7" title-active-color="#06A44F">
          <van-tab class="tab" title="产品介绍">
            <div v-html="htmlContent" class="html-content"></div>
          </van-tab>
          <van-tab class="tab msg" title="联络资料">
            <div class="one">
              <p class="title">联系资料</p>
              <div v-for="(item,key) in hospitals" :key="key"> 
                <p class="name">{{item.name}}</p>
                <span>地址：&nbsp;&nbsp;{{item.address}}</span>
                
              </div>
            </div>
              <!--
              <span>电话：&nbsp;&nbsp;{{hospital.phone}}</span>
              <span>传真：&nbsp;&nbsp;{{hospital.fax}}</span>
              <span>邮箱：&nbsp;&nbsp;{{hospital.email}}</span>
              
            
            <div class="two">
              <p>就诊时间</p>
              <p>{{hospital.time}}</p>
              <p>公眾假期：{{hospital.holiday}}</p>
            </div>
            -->
          </van-tab>
          <van-tab class="tab" title="评价">
            <div class="comment" v-for="(item, key) in commentList" :key="key">
              <img :src="item.head_img" />
              <p class="comment-username" v-html="item.name" />
              <p class="comment-text" v-html="item.comment" />
              <p class="comment-date" v-html="item.CreatedAt" />
            </div>
          </van-tab>
        </van-tabs>
      </section>
    </div>
    <div class="footer">
      <div class="server">
        <img src="/static/img/server.png" alt />
      </div>
      <button @click="appointment" class="btn">预约</button>
    </div>
  </div>
</template>

<script>

import NavBar from "@/components/nav/navBar";
import { domain, search } from '@/api'
import axios from 'axios'
import { wxshare } from './../../wxconf'
import Axios from 'axios';
const img = "http://www.likehealth.com.cn"
export default {
  components: {
    NavBar
  },
  data() {
    return {
      FixedRate: {
        HK:0.92,
      },
      commentList: [],
      hospitals: [{
        name: "",
        address: "",
      }],
      showImg: false,
      imgList: [""],
      price: "",
      vipPrice: "",
      department: {
        name: "",
        detail:""
      },
      htmlContent: ``,
      availHeight: { height: "0" },
      belong_hos:'',
      productTemp:{}
    };
  },
  created(){
    axios.get(domain+"/api/old/pingjia/product/list?ke_jieshao_id="+search("id"))
    .then((res)=>{
      if(res.data.code == 1){
        this.commentList = res.data.data
      }
    })
    .catch((err)=>{

    })
    axios.post(domain+"/api/FixedRate")
    .then((res)=>{
      this.FixedRate = res.data.data
      axios.post(domain+"/api/old/product/one?id="+search("id"))
      .then((res)=>{
        if(res.data.code==1){
          wxshare(res.data.data.cat_name, res.data.data.intro, res.data.data.img_url, window.location.href, function(){
            console.log('设置成功')
          })
          this.productTemp = res.data.data
          this.imgList = res.data.data.goods_thumb.split(",")
          this.department.name = res.data.data.cat_name
          this.department.detail = res.data.data.intro
          this.htmlContent = `<!DOCTYPE html>
            <style>
            html{
              
            }
            img{
              width: 100%;
            }
            .f0{
              width: 100%;
              font-size:0
            }
            </style>
            <body>
              <div class="f0">`
              +res.data.data.introduction +
              `  </div>

            </body>
            </html>`
            // 汇率换算
          this.price = Math.round(res.data.data.price*this.FixedRate.HK/10)*10
          this.vipPrice = Math.round(res.data.data.price*this.FixedRate.HK/10)*10*((100-13)/100)
          // 设置医院地址
          this.belong_hos = res.data.data.belong_hos
          axios.get(domain+"/api/old/hospital/address?id="+res.data.data.belong_hos)
          .then((res)=>{
            if(res.data.code == 1){
              this.hospitals = res.data.data
            }
          })
          .catch((err)=>{

          })
        }
      })
      .catch((err)=>{

      })
    })
    .catch((err)=>{

    })
    
  },
  mounted() {
    this.availHeight = { height: `${window.screen.availHeight}px` };
    this.showImg = this.imgList.length > 0;
  },
  methods: {
    collection() {
      axios.post(domain+'/api/old/collection?ke_jieshao_id='+search("id")+"&product_from="+search("product_from"))
      .then((res)=>{
        if(res.data.code==1){
          this.$dialog.alert({ message: "收藏成功" })
        }else{
          this.$dialog.alert({ title: res.data.msg, message: res.data.err })
        }
      })
      .catch((err)=>{
        this.$dialog.alert({ title: '提示', message: err })
      })
    },
    appointment() {
      window.location.href = "/product/order?id="+search("id")+"&product_from="+search("product_from")+"&haid="+this.belong_hos
    }
  }
};
</script>

<style lang='scss' scoped>
.goto-list {
  font-size: 11px;
  font-family: Microsoft YaHei;
  font-weight: 400;
  color: rgba(255, 255, 255, 1);
  line-height: 1em;
  position: fixed;
  z-index: 210;
  top: 16px;
  right: 14px;
  z-index: 210;
}
.productDetail {
  overflow: hidden;
  overflow-y: auto;
  height: 100%;
  padding-bottom: 50px;
  .gap {
    margin-top: 46px;
    padding-bottom: 50px;
    
    .img {
      width: 320px;
      height: 172px;
      img {
        width: 100%;
        height: 100%;
      }
    }
    .department {
      width: 300px;
      margin: 9px 11px 9px 8px;
      .product-price {
        font-size: 16px;
        font-family: Microsoft YaHei;
        font-weight: 400;
        color: rgba(255, 80, 0, 1);
        line-height: 1em;
        margin: 0;
      }
      .vip-price {
        font-size: 10px;
        font-family: Microsoft YaHei;
        font-weight: 400;
        color: rgba(102, 102, 102, 1);
        line-height: 1em;
        margin: 0;
        margin-top: 9px;
      }
      .department-name {
        font-size: 12px;
        font-family: Microsoft YaHei;
        font-weight: bold;
        color: rgba(51, 51, 51, 1);
        margin: 0;
        line-height: 1em;
        margin-top: 11px;
      }
      .department-detail {
        margin-top: 6px;
        font-size: 11px;
        font-family: Microsoft YaHei;
        font-weight: 400;
        color: rgba(102, 102, 102, 1);
        line-height: 1.3em;
      }
    }
    .tabs {
      overflow: auto;
      // padding: 0;
      .html-content {
        font-size:0;
        overflow: hidden;
        overflow-y: auto;
        width: 100%;
      }
      .msg {
        .one,
        .two {
          margin-left: 9px;
          margin-right: 9px;
        }
        .two {
          font-size: 13px;
          font-family: Microsoft YaHei;
          font-weight: 400;
          color: rgba(0, 0, 0, 1);
          line-height: 26px;
          p {
            white-space: pre-wrap;
            margin: 0;
          }
        }
        .one {
          margin-top: 14px;
          padding-bottom: 8px;
          border-bottom: 1px solid #f5f5f7;
          margin-bottom: 6px;
          p {
            margin: 0;
            font-size: 13px;
            font-family: Microsoft YaHei;
            font-weight: 400;
            color: rgba(0, 0, 0, 1);
          }
          .name {
            font-size: 13px;
            font-family: Microsoft YaHei;
            font-weight: bold;
            color: rgba(12, 83, 139, 1);
            margin: 6px 0 8px 0;
          }
          span {
            font-size: 12px;
            font-family: Microsoft YaHei;
            font-weight: 400;
            color: rgba(102, 102, 102, 1);
            display: block;
            line-height: 18px;
          }
        }
      }
      .comment {
        margin: 4px 11px 5px 9px;
        padding-bottom: 5px;
        min-height: 44px;
        position: relative;
        width: 300px;
        border-bottom: 1px solid #f5f5f7;
        &:last-child {
          margin-bottom: 55px;
          border-bottom: none;
        }
        img {
          position: absolute;
          width: 32px;
          height: 32px;
          border-radius: 50%;
          top: 0px;
          left: 0px;
        }
        .comment-username {
          margin: 10px 0 0 40px;
          width: 250px;
          font-size: 12px;
          font-family: Microsoft YaHei;
          font-weight: 400;
          color: rgba(59, 59, 59, 1);
          line-height: 1em;
        }
        .comment-text {
          margin: 5px 0 0 40px;
          width: 250px;
          font-size: 11px;
          font-family: Microsoft YaHei;
          font-weight: 400;
          color: rgba(59, 59, 59, 1);
          line-height: 18px;
        }
        .comment-date {
          margin: 0;
          position: absolute;
          top: 0;
          right: 0px;
          font-size: 9px;
          font-family: Microsoft YaHei;
          font-weight: 400;
          color: rgba(102, 102, 102, 1);
          line-height: 1em;
        }
      }
    }
  }
  .footer {
    position: fixed;
    bottom: 0;
    width: 320px;
    height: 40px;
    display: flex;
    z-index: 101;
    .server {
      width: 52px;
      height: 100%;
      background: #e6e6e6;
      text-align: center;
      hr {
        margin: 0;
      }
      img {
        width: 17px;
        height: 17px;
        margin-top: 11.5px;
      }
    }
    .btn {
      border: none;
      width: 268px;
      height: 40px;
      background: #259b23;
      font-size: 13px;
      font-family: Microsoft YaHei;
      font-weight: 400;
      color: rgba(255, 255, 255, 1);
    }
  }
}
</style>
<style>
.productDetail .tabs .van-tabs__nav {
  border: 1px solid #f5f5f7;
  margin: 0;
}
.productDetail .tabs .van-tab {
  color: #000;
  border: none;
}
.productDetail .tabs .van-tab.van-tab--active {
  background: #fff;
}
</style>